﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Pavilion.DesignerTool.ViewTools
{
    public class PropertyCategory
    {
        public string CatergoryName { get; set; }
        public IEnumerable<PropertyItemBase> Properties { get { return properties; } }
        public object AssociatedItem { get; private set; }

        private NotifiableCollection<PropertyItemBase> properties;

        public PropertyCategory(object associatedItem)
        {
            this.AssociatedItem = associatedItem;
            this.CatergoryName = AssociatedItem.ToString();
            properties = new NotifiableCollection<PropertyItemBase>();
        }

        public void AddProperty(PropertyItemBase property)
        {
            properties.Add(property);
        }

        public void RemoveProperty(PropertyItemBase property)
        {
            properties.Remove(property);
        }

        public void RemoveProperty(string propertyName)
        {
            IEnumerable<PropertyItemBase> propertiesToRemove = properties.Where(x => x.PropertyName == propertyName).ToArray();

            foreach (PropertyItemBase property in propertiesToRemove)
                RemoveProperty(property);
        }

        public void Clear()
        {
            properties.Clear();
        }
    }
}
